Typical Usage:
Required bean name is "ASL1".
There are the following three typical usage modes:
(1)
The simplest usage of the bean is a communication without interrupts (polling mode).
MAIN.C
byte ch;
byte err;
ASL1_TError error;
void main(void)
{
for(;;) {
//Wait for a character.
//The slave must be selected by a master first.
while(ASL1_GetCharsInRxBuf() == 0);
//Read received character and send it if the slave is selected
//and no error is detected
if( ASL1_RecvChar(&ch) == ERR_OK) {
ASL1_SendChar(ch);
} else {
// The GetBreak method must be used first because
// the GetError method clear the break flag
// This method is available if the Break
// signal is enabled (Advanced view).
ASL1_GetBreak(&b);
if (b) {
// the break character was received
}
ASL1_GetError(&error)
if(error.errName.Parity)
//Parity error
else if(error.errName.Framing)
//Framing error
.
.
.
}
}
}
(2)
The next typical usage of this bean is a communication with interrupts using communication events.
EVENTS.C
void ASL1_OnRxChar(void)
{
byte ch;
//Read received character and if no error is detected
if(ASL1_RecvChar(&ch) == ERR_OK)
ASL1_SendChar(ch); //send it back
}
(3)
Following example shows how to recognize a communication error using the GetError method.
In the interrupt communication mode the user can use the OnError event to recognize an error during
the communication.
MAIN.C
byte ch;
ASL1_TError error; //TError union is defined in the header file
void main(void)
{
while(ASL1_GetCharsInRxBuf() == 0); //Wait for a character
ASL1_RecvChar(&ch); //Read received character
//Read the last communication errors
ASL1_GetError(&error)
if(error.err == 0) {
//Send the last received character if no error is detected
ASL1_SendChar(ch);
} else {
if(error.errName.Parity) {
//Parity error
} else if(error.errName.Framing) {
//Framing error
}
.
.
}
.
.
}
For more about typical usage of the bean code please refer to the page Bean Code Typical Usage.
|